<?php
// +----------------------------------------------------------------------
// | Copyright © Sogu Technologies Co. Ltd 2018-2050 All rights reserved.
// +----------------------------------------------------------------------
// | File name: AvatorRequest.php
// +----------------------------------------------------------------------
// | Author: liuju
// +----------------------------------------------------------------------
// | Description: 描述文档功能
// +----------------------------------------------------------------------
// | Others: 其他内容的说明
// +----------------------------------------------------------------------
// | History: 修改历史记录列表，每条修改记录应包含修改日期、修改者及修改内容简述
// +----------------------------------------------------------------------
// | 1.Date: 2018-12-29 Author: liuju Modification: 创建
// +----------------------------------------------------------------------

namespace App\Http\Requests\Frontend\V10\Risk;


use Illuminate\Foundation\Http\FormRequest;

class RiskRequest extends FormRequest {
    public $routeName;

    public function __construct() {
        $this->routeName = \Route::currentRouteName();
        parent::__construct();
    }

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize() {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules() {
        switch ($this->routeName) {
            case 'risk.apply':
                return $this->applyRules();
                break;
            case 'risk.spider':
                return $this->spiderRules();
                break;
            case 'risk.query':
                return $this->queryRules();
                break;
            default:
                return [];
        }
    }

    public function applyRules() {
        return [
            'device_id'   => 'required',
            'device_type' => 'required|integer|in:1,2,3',
        ];
    }

    public function spiderRules() {
        return [
            'type' => 'required|in:1,2',
        ];
    }

    public function queryRules() {
        return [
            'risk_id' => 'required',
        ];
    }


    public function messages() {
        switch ($this->routeName) {
            case 'risk.apply':
                return $this->applyMessages();
                break;
            case 'risk.spider':
                return $this->spiderMessages();
                break;
            case 'risk.query':
                return $this->queryMessages();
                break;
            default:
                return [];
        }
    }

    public function spiderMessages() {
        return [
            'type.required' => '爬虫类型不能为空',
            'type.in'       => '爬虫类型错误',
        ];
    }

    public function applyMessages() {
        return [
            'device_id.required'   => '设备号不能为空',
            'device_type.required' => '设备类型不能为空',
            'device_type.integer'  => '设备类型数据类型错误',
            'device_type.in'       => '设备类型错误',
        ];
    }

    public function queryMessages() {
        return [
            'risk_id.required' => '风控查询ID不能为空',
        ];
    }
}